import { createStore, Store, useStore as useVuexStore } from 'vuex'
import type { IRootState, IStoreType } from './types'
import login from './login/login'
import system from './system/system'

const store = createStore<IRootState>({
  state() {
    return {
      name: 'laiht',
      age: 18,
      height: 180
    }
  },
  mutations: {
    setName(state, payload: string) {
      console.log(state)
      state.name = payload
    }
  },
  getters: {},
  actions: {},
  modules: {
    login,
    system
  }
})

// console.log(store.state.name)
export function setLocalData() {
  store.dispatch('login/setLocalData')
}

export function useStore(): Store<IStoreType> {
  return useVuexStore()
}

export default store
